import { call, put, takeEvery } from 'redux-saga/effects';
import * as actionTypes from '@src/model/actionType';
import * as API from '@src/api/index';
import { get as _get } from 'lodash';

function* fetchTxList(action) {
  const params = _get(action, ['params'], {});
  try {
    const data = yield call(API.getTxList, params);
    yield put({
      type: actionTypes.txList,
      payload: {
        TotalCount: _get(data, ['TotalCount'], 0),
        GroupList: _get(data, ['GroupList'], []),
      },
    });
  } catch (err) {
    console.error(err);
  }
}

const sagas = [takeEvery(actionTypes.fetchTxList, fetchTxList)];

export default sagas;
